home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / 8bit / cislib_a / center.doc < prev    next >
Text File  |  1995-04-22  |  2KB  |  55 lines

  1. CENTER LINE ROUTINE
  2.  
  3. Ever since I started programming with BASIC a few years ago, 
  4. I've always spent massive amounts of time and energy just 
  5. positioning text on the screen.  For instance, I would have a 
  6. statement that centered something on the screen.  For 
  7. instance,
  8.  
  9.         WriteLn('             Welcome to my program.');
  10.  
  11. is just about appropriate to center the text on a 40-column 
  12. screen such as the Atari's.  The annoying thing about writing 
  13. statements such as the above WriteLn is that spaces would 
  14. have to be padded to center the text, and finding the correct 
  15. number of spaces to pad was quite a chore.  If I were to 
  16. later change just the text in that statement to:
  17.  
  18.         WriteLn('             Hi there.');
  19.  
  20. then it would no longer be centered on the screen, and I 
  21. would have to recalculate the number of leading spaces to 
  22. pad.  That is not what a good programmer would call 
  23. maintainable code.  So for years of spending countless hours 
  24. on simple PRINT and WriteLn statements, I always said to 
  25. myself "someday I'm going to write a routine to automate all 
  26. this, and save myself some trouble."  Not long ago, I finally 
  27. got around to writing that routine while programming a 
  28. database system with SuperCharged Pascal under Mess-DOS on a 
  29. Me-2 Clone computer (names of compiler, operating system, and 
  30. computer changed to protect the guilty).  I've transferred 
  31. the routine to the Atari, again demonstrating Pascal's 
  32. portability.
  33.  
  34. Center is a relatively simple routine which requires three 
  35. parameters, the first of which is a string.  The string 
  36. passed must have been declared as the following data TYPE:
  37.  
  38.         String = ARRAY[1..MaxString] OF Char;
  39.  
  40. As you can see, you must have previously assigned the 
  41. CONSTant MaxString a value.  The next parameter passed must 
  42. be a VARiable (not a constant or value) of TYPE Integer.  It 
  43. will be changed to reflect the horizontal position (of the 
  44. first character in your string) at which the string was 
  45. written to on the screen.  The final parameter is an Integer 
  46. again, this one being the vertical position at which you want 
  47. your string centered.  Remember that you must include (#i) 
  48. the files LENGTH.I and POSITION.I before you include the 
  49. Center procedure.  Here is an example of calling Center:
  50.  
  51.         Center(MyString,x,y);
  52.  
  53. (CENTER.PAS should be renamed to CENTER.I after downloading.)
  54.  
  55.